'''
Created on Oct 21, 2009

@author: Stanly
'''
from subprocess import *
import logging

log = logging.getLogger(__name__)

def run_command(command, **kwargs):
	log.debug('running command: %s + %s' % (command, kwargs) )
	try:
		child = Popen(command, **kwargs)
		child.wait()
		out = ''.join(child.stdout.readlines())
		out += ''.join(child.stderr.readlines())
		return (child.returncode, out)
	except Exception, ex:
		log.fatal('run_command: %s - %s' % str(ex), str(ex.args))
		return 128, str(ex)